package com.example.service.impl;

import com.example.service.SendEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;


@Service
public class SendEmailServiceImpl implements SendEmailService {

    @Autowired
    private JavaMailSender javaMailSender;

    //发送者
    private String from = "2242551679@qq.com";
    //主题
    private String subject="验证码";
    //正文
    private String content = "以下便是你的验证码，请尽快使用";

    @Override
    public String sendEmail(String to) {
        //随机生成六位数
        Integer code = (int)(Math.random()*900000+100000);
        SimpleMailMessage message = new SimpleMailMessage();
        //添加后将发件人变成了神秘人    !!!  必须带括号不然报错
        message.setFrom(from+"(宠爱有家)");
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content+":"+code.toString());
        javaMailSender.send(message);
        return code.toString();
    }

    @Override
    public void sendEmailservice(String content,String address) {
        //主题
        subject = "您的服务预约情况";
        SimpleMailMessage message = new SimpleMailMessage();
        //添加后将发件人变成了神秘人    !!!  必须带括号不然报错
        message.setFrom(from+"(宠爱有家)");
        message.setTo(address);
        message.setSubject(subject);
        message.setText(content);
        javaMailSender.send(message);
    }

}
